package com.newshub.ai.model.dto;

import lombok.Data;
import java.time.LocalDateTime;

/**
 * 聊天响应DTO
 */
@Data
public class ChatResponse {

    /**
     * 响应ID
     */
    private String id;

    /**
     * AI回复内容
     */
    private String content;

    /**
     * 使用的模型
     */
    private String model;

    /**
     * 响应时间
     */
    private LocalDateTime timestamp;

    /**
     * 是否成功
     */
    private Boolean success = true;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 使用的token数量
     */
    private TokenUsage tokenUsage;

    /**
     * 响应元数据
     */
    private ResponseMetadata metadata;

    /**
     * Token使用情况
     */
    @Data
    public static class TokenUsage {
        private Long promptTokens;
        private Long completionTokens;
        private Long totalTokens;
    }

    /**
     * 响应元数据
     */
    @Data
    public static class ResponseMetadata {
        private String finishReason;
        private Double temperature;
        private Integer maxTokens;
        private Long responseTime;
    }

    /**
     * 完成原因
     */
    private String finishReason;

    /**
     * 创建成功响应
     */
    public static ChatResponse success(String content, String model) {
        ChatResponse response = new ChatResponse();
        response.setContent(content);
        response.setModel(model);
        response.setSuccess(true);
        response.setTimestamp(LocalDateTime.now());
        return response;
    }

    /**
     * 创建错误响应
     */
    public static ChatResponse error(String errorMessage) {
        ChatResponse response = new ChatResponse();
        response.setSuccess(false);
        response.setErrorMessage(errorMessage);
        response.setTimestamp(LocalDateTime.now());
        return response;
    }
}

